package com.taoxi.good.controller;

import com.taoxi.common.annotation.Log;
import com.taoxi.common.core.controller.BaseController;
import com.taoxi.common.core.domain.AjaxResult;
import com.taoxi.common.core.page.TableDataInfo;
import com.taoxi.common.enums.BusinessType;
import com.taoxi.common.utils.poi.ExcelUtil;
import com.taoxi.good.domain.GoodSku;
import com.taoxi.good.service.IGoodSkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * sku管理testController
 *
 * @author ruoyi
 * @date 2024-10-21
 */
@Api(tags = "sku管理testController")
@RestController
@RequestMapping("/good/sku")
public class GoodSkuController extends BaseController {
    @Autowired
    private IGoodSkuService goodSkuService;

    /**
     * 查询sku管理test列表
     */
    @ApiOperation("查询sku管理test列表")
    @PreAuthorize("@ss.hasPermi('good:sku:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodSku goodSku) {
        startPage();
        List<GoodSku> list = goodSkuService.selectGoodSkuList(goodSku);
        return getDataTable(list);
    }

    /**
     * 导出sku管理test列表
     */
    @ApiOperation("导出sku管理test列表")
    @PreAuthorize("@ss.hasPermi('good:sku:export')")
    @Log(title = "sku管理test", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodSku goodSku) {
        List<GoodSku> list = goodSkuService.selectGoodSkuList(goodSku);
        ExcelUtil<GoodSku> util = new ExcelUtil<GoodSku>(GoodSku.class);
        util.exportExcel(response, list, "sku管理test数据");
    }

    /**
     * 获取sku管理test详细信息
     */
    @ApiOperation("获取sku管理test详细信息")
    @PreAuthorize("@ss.hasPermi('good:sku:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(goodSkuService.selectGoodSkuById(id));
    }

    /**
     * 新增sku管理test
     */
    @ApiOperation("新增sku管理test")
    @PreAuthorize("@ss.hasPermi('good:sku:add')")
    @Log(title = "sku管理test", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodSku goodSku) {
        return toAjax(goodSkuService.insertGoodSku(goodSku));
    }

    /**
     * 修改sku管理test
     */
    @ApiOperation("修改sku管理test")
    @PreAuthorize("@ss.hasPermi('good:sku:edit')")
    @Log(title = "sku管理test", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodSku goodSku) {
        return toAjax(goodSkuService.updateGoodSku(goodSku));
    }

    /**
     * 删除sku管理test
     */
    @ApiOperation("删除sku管理test")
    @PreAuthorize("@ss.hasPermi('good:sku:remove')")
    @Log(title = "sku管理test", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(goodSkuService.deleteGoodSkuByIds(ids));
    }
}
